package v9.assist.analyst

import android.graphics.Bitmap
import abc.reflect.App
import kotlinx.coroutines.script.Block
import kotlinx.coroutines.script.TARGET
import kotlinx.coroutines.script.analysis.Analysis
import kotlinx.coroutines.script.SMapBase.hitBlueDoor
import kotlinx.coroutines.script.SMapBase.hitBox
import kotlinx.coroutines.script.SMapBase.hitDeathRed
import kotlinx.coroutines.script.SMapBase.hitEquipO
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyBlue
import kotlinx.coroutines.script.SMapBase.hitSMapEnemyYellow
import kotlinx.coroutines.script.SMapBase.hitTeammate
import kotlinx.coroutines.script.tes.ColorDiffer
import kotlinx.coroutines.script.tes.containsSimilarColor
import kotlinx.coroutines.script.tes.printLog
import kotlinx.coroutines.script.tes.pt
import kotlinx.coroutines.script.tes.rgb
import kotlinx.coroutines.script.tes.shake
import v9.assist.script.xBossBesideTs

import v9.assist.script.xLastAtkTs
import v9.assist.script.xLastPetBlacksmithTs
import v9.assist.script.xLastSceneEnterTs
import v9.assist.script.xLastUnknownTs
import kotlin.math.abs

private val hitBridge by lazy {
    val bridge = setOf(
        0xff65523f.toInt().rgb(12),
        0xff766753.toInt().rgb(12),
        0xff8F7D64.toInt().rgb(12),
        0xff918168.toInt().rgb(12),
    )
    val out = mutableSetOf<ColorDiffer>()
    out.addAll(bridge)
    out.addAll(hitDeathRed)
    out.addAll(hitTeammate)
    out
}
private val hitRoad by lazy {
    val out = mutableSetOf<ColorDiffer>()
    out.addAll(setOf(0xff3f3a2b.toInt().rgb(12))) //旧的还没出错
    out.addAll(setOf(0xff494332.toInt().rgb(12))) //开局新路
    out.addAll(setOf(0xff4a4236.toInt().rgb(12))) //开局新路
    out.addAll(setOf(0xff4c3b2a.toInt().rgb(12))) //瀑布下船 辅路
    out.addAll(setOf(0xff564531.toInt().rgb(12))) //瀑布下船 主路
    out.addAll(hitBridge)
    out.addAll(hitEquipO)
    out.addAll(hitBox)
    out.addAll(hitSMapEnemyYellow)
    out.addAll(hitSMapEnemyBlue)
    out
}

var anaLastSMapJLFeature6Ts = 0L // 满足一些地图边缘特征条件.再断定村子
var blockSJLVillage: Block? = null

var anaLastSMapJLFeature1Ts = 0L // 村子外木桥
var anaLastSMapJLFeature2Ts = 0L // 村子内上船
var anaLastSMapJLFeature3Ts = 0L // 村子外宝箱岔路
var anaLastSMapJLFeature4Ts = 0L // 副本外入口
var anaLastSMapJLFeature5Ts = 0L // 木筏上往左上角跑.增加一个80秒的随机方向移动
var anaLastSMapJLFeature7Ts = 0L // 直通特征
var anaLastSMapJLFeature8Ts = 0L // 副本起点
var anaLastSMapJLFeature9Ts = 0L // 木筏上回头扫荡
var anaLastSMapJLFeature10Ts = 0L

fun analysisMapElementsJL(ss: Bitmap) {
    blockSJLVillage = null
    analysisMapElements(ss, baseAnalysisBlueDoor = false) { x, y ->
        val color = App.take().takePixel(ss, x, y)
        if (blockBlueDoor == null
            && bsSceneSettle
            && x > smallMap.left + 100.pt && y < smallMap.bottom - 100.pt
            && hitBlueDoor.containsSimilarColor(color)) {
            val check = Block("小地图传送门b", x , y, 16.pt, 16.pt) //
            if (Analysis.hit(ss, check, hitBlueDoor, 2.pt, 0.24f)) {  // Boss这里的门容易误判
                blockBlueDoor = check
                lastBlueDoorTs = System.currentTimeMillis()
            }
        } else if (blockBlueDoor == null
            && !bsSceneSettle
            && hitBlueDoor.containsSimilarColor(color)) {
            val check = Block("小地图传送门", x , y, 16.pt, 16.pt) //
            if (Analysis.hit(ss, check, hitBlueDoor, 2.pt, 0.24f)) {  // Boss这里的门容易误判
                blockBlueDoor = check
                lastBlueDoorTs = System.currentTimeMillis()
            }
        }
        if (blockSJLVillage == null
            && System.currentTimeMillis() - xLastSceneEnterTs > 20000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 20000
            && System.currentTimeMillis() - lastMapTopNotArrivedTs > 3000
            && hitBridge.containsSimilarColor(color)
            && !bsSceneSettle && !bsSceneSettleBlacksmith) {
            // && (x > smallMap.right - 110.pt && y < smallMap.top + 110.pt)  // 右上角
            if ((x > selfInSmallMap.x - 40.pt && y < smallMap.bottom - 80.pt)) { // 在右边即可
                // hit [村子桥] 0.8888889 hitCount 72 total 81
                val out = Block("bridge", x, y, 16.pt, 16.pt)
                if (Analysis.hit(ss, out, hitBridge, 4.pt, 0.68f)) { // 0.8 , "村子桥" //0.72f->0.68f
                    printLog { "analyst hit [发现村子]" }
                    blockSJLVillage = out
                    anaLastSMapJLFeature6Ts = System.currentTimeMillis()
                }
            }
        }
    }
}

fun rasterizeMapJL(ss: Bitmap): Array<IntArray> {
    return rasterizeMap(ss, hitRoad)
}

fun analysisMapJL(ss: Bitmap) {
    //printLog { "analysisMapJL" }
    // pre redo refix 通关有异常的O
    if (bsEnemy == "O" || bsEnemy == "R") {
        if (System.currentTimeMillis() - anaLastHasEnemyBossNameTs < 8000
            || System.currentTimeMillis() - lastBlueDoorTs < 4000
            || System.currentTimeMillis() - lastBlacksmithTs < 4000) {
            enemy = ""
        }
    }

    analysisMapElementsJL(ss)
    val returnMapArray = rasterizeMapJL(ss)

    if (blockEliteEnemyBoss != null && mapEnemyList.isNotEmpty()) {
        // 优先Boss
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to boss" }
        lastSMapTargetToBossTs = System.currentTimeMillis()
        if (mapElementDistance(blockEliteEnemyBoss) < 30.pt) xBossBesideTs = System.currentTimeMillis()
    } else if (mapEnemyList.isNotEmpty()
        && System.currentTimeMillis() - anaLastSMapJLFeature4Ts > 10000 // 在副本外面的误判导致没有开始
        && System.currentTimeMillis() - anaLastPageSceneEnterTs > 10000 // 刚开局就需要
        && System.currentTimeMillis() - anaLastSceneSettleTs > 20000
        && System.currentTimeMillis() - xLastUnknownTs > 10000
        && !bsSceneSettle && !bsSceneSettleBlacksmith) {
        // 优先敌人
        mapTargetList.add(mapEnemyList.random())
        printLog { "analyst target to elite enemy" }
    } else if (bsSceneSettleBlacksmith && mapBlacksmithList.isNotEmpty()) {
        mapTargetList.add(mapBlacksmithList.random())
        printLog { "analyst target to blacksmith" }
        // 这个传送门高几率是瀑布区域的误判
//    } else if (bsSceneSettle && mapBlueDoorList.isNotEmpty()) {
//        mapTargetList.add(mapBlueDoorList.random())
//        printLog { "analyst target to blueDoor" }
    } else if (mapTopNotArrived.isNotEmpty()) {
        mapTargetList.add(mapTopNotArrived.random())
        //printLog { "analyst target to top" }
    } else if (mapRightNotArrived.isNotEmpty()) {
        mapTargetList.add(mapRightNotArrived.random())
        //printLog { "analyst target to right" }
    } else if (mapSampleArrived.isNotEmpty()) {
        if (System.currentTimeMillis() - lastEliteEnemyBossTs < 12000) {
            mapSampleArrived.filter { it.second < selfInSmallMap.y - smallMap.top }
                .minByOrNull { it.second }?.also {
                    mapTargetList.add(it) //
                    printLog { "analyst target to sample top after boss" }
                }
        } else {
            mapSampleArrived.filter {
                it.first > selfInSmallMap.x - smallMap.left
            }.randomOrNull()?.also {
                mapTargetList.add(it)
                printLog { "analyst target to sample right" }
            }
        }
    }

    if (mapTargetList.isNotEmpty()) {
        val target = mapTargetList.random()
        returnMapArray[target.first][target.second] = TARGET
    }

    angleByRoad = analysisRasterizeMap(returnMapArray)
    angleByRoad = angleSpecialAdjust(angleByRoad ?: 62.shake(15))
    printLog { "accPathfinding analystJL angleByRoad $angleByRoad" }

    // map feature
    analysisMapJLIsStartPoint(ss)

    if ((blockBlueDoor == null || blockBlacksmith == null)) {
        printLog { "analystJL $mapSimpleStatus" }
        if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.41 .. 0.53
            && (lastMapBottomP ?: -1f) in 0.31 .. 0.43
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.61 .. 0.73
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            //  [上(0s,0.46479791395045633][下(0s,0.3601694915254237][左(1736682778s][右(0s,0.6602564102564102]
            printLog { "analystJL 节点.村子口木桥右侧" }
            anaLastSMapJLFeature1Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && (lastMapBottomP ?: -1f) in 0.01 .. 0.26
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.25 .. 0.45
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            //  [上(17s][下(0s,0.11440678][左(26s][右(0s,0.3525641]
            printLog { "analystJL 节点.村子口绳索前" }
            anaLastSMapJLFeature2Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapTopP ?: -1f) in 0.13 .. 0.31
            && lastMapBottomP == null
            && (lastMapLeftP ?: -1f) in 0.28 .. 0.62
            && lastMapRightP == null
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            // [上(0s,0.14530046][下(1736868215s][左(0s,0.31739432][右(1736868215s]
            // [上(0s,0.26828086][下(1736783564s][左(0s,0.5789909][右(1736783564s]
            // [上(0s,0.27274755][下(1736783590s][左(0s,0.55334985][右(1736783590s]
            // [上(0s,0.25928596][下(1736783826s][左(0s,0.4785624][右(1736783826s] 传送门
            printLog { "analystJL 节点.副本外入口" }
            anaLastSMapJLFeature4Ts = System.currentTimeMillis()
            anaClearSceneSettle() // [重要.结算失败.角色跑出去了]重置掉结算状态
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && lastMapTopP == null
            && lastMapBottomP == null
            && (lastMapLeftP ?: -1f) in 0.44 .. 0.54
            && lastMapRightP == null
            && System.currentTimeMillis() - lastBlacksmithTs > 3000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            // [上(1736683451s][下(1736683451s][左(0s,0.49358973][右(1736683451s]
            // 这个在副本外入口之下判断.
            // 这个在副本外入口之下判断.
            // 这个在副本外入口之下判断.
            // 这个在副本外入口之下判断.  不然在起点外走这个逻辑就出去了
            printLog { "analystJL 节点.村子前宝箱岔路" } // 这个在副本外入口之下判断.
            anaLastSMapJLFeature3Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs > 2000
            && (lastMapTopP ?: -1f) in 0.22 .. 0.38
            && lastMapTopC in 20 .. 100  // 单刷是50多个
            && (lastMapBottomP ?: -1f) in 0.16 .. 0.44
            && lastMapBottomC in 20 .. 100 // 单刷是50多个
            && lastMapRightP == null
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            // 否 count太少 [上,0s,0.24293785,c:6][下,0s,0.21876961,c:9][左,10s,c:0][右,19s,c:0]][Road,c:10]
            printLog { "analystJL 节点.木筏碰撞转向点" }
            // 真[上,0s,0.3666849,c:31][下,0s,0.16894478,c:31][左,0s,0.87393165,c:4][右,7s,c:0]][Road,c:12]
            // [上,0s,0.33892295,c:47][下,0s,0.43131718,c:51][左,6s,c:0][右,16s,c:0]][Road,c:33]
            // 这个出现了3次.就是这个节点
            // analystJL [上(0s,0.27966103,c:54][下(0s,0.17270602,c:58] 左不管 [左(0s,0.9444444,c:1][右(9s,c:0]]
            // [上,0s,0.28254354,c:49][下,0s,0.26351896,c:56][左,3s,c:0][右,12s,c:0]][Road,c:36]
            anaLastSMapJLFeature5Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && lastMapBottomP == null
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.14 .. 0.36
            && System.currentTimeMillis() - lastBlueDoorTs < 2000
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 15000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            printLog { "analystJL 节点.直通" }
            // 有蓝怪的2种
            // [上,1737463993s,c:0][下,1737463993s,c:0][左,1737463993s,c:0][右,0s,0.18764569,c:11]][Road,c:21]
            // [上,1737463986s,c:0][下,1737463986s,c:0][左,1737463986s,c:0][右,0s,0.21225072,c:12]][Road,c:21]
            // 蓝怪干死
            // [上,10s,c:0][下,17s,c:0][左,12s,c:0][右,0s,0.2994918,c:37]][Road,c:24]
            anaLastSMapJLFeature7Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapTopNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapTopP ?: -1f) in 0.70 .. 0.90
            && (lastMapBottomP ?: -1f) in 0.18 .. 0.32
            && (lastMapRightP ?: -1f) in 0.06 .. 0.15
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 6000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 10000
        ) {
            // [上,0s,0.8600518,c:24][下,0s,0.1940844,c:34][左,0s,0.8888889,c:1][右,0s,0.13354701,c:4]][Road,c:12]
            printLog { "analystJL 节点.木筏上回头扫荡" }
            // [上,0s,0.7655367,c:80][下,0s,0.24011299,c:52][左,3s,c:0][右,0s,0.123931624,c:18]][Road,c:52]
            // [上,0s,0.7683258,c:79][下,0s,0.22810735,c:48][左,7s,c:0][右,0s,0.09145299,c:10]][Road,c:44]
            // [上,0s,0.8530497,c:49][下,0s,0.30037665,c:42][左,0s,0.9017094,c:2][右,0s,0.102564104,c:12]][Road,c:50]
            //  [上,0s,0.7570281,c:83][下,0s,0.21797533,c:49][左,15s,c:0][右,0s,0.10683761,c:14]][Road,c:50]
            anaLastSMapJLFeature9Ts = System.currentTimeMillis()
        } else if (System.currentTimeMillis() - lastMapBottomNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs < 1000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && (lastMapBottomP ?: -1f) in 0.11 .. 0.21
            && (lastMapLeftP ?: -1f) in 0.68 .. 0.78
            && (lastMapRightP ?: -1f) in 0.24 .. 0.32
            && System.currentTimeMillis() - xLastUnknownTs > 6000
            && System.currentTimeMillis() - xLastSceneEnterTs > 6000
        ) {
            printLog { "analystJL 节点.激流Boss前卡角" }
            // 上无视不判断Boss图标干扰 [上,0s,0.85075325,c:12][下,0s,0.16758639,c:43][左,0s,0.73504275,c:38][右,0s,0.28116712,c:29]][Road,c:62]
            anaLastSMapJLFeature10Ts = System.currentTimeMillis()
        }
    }

    if (System.currentTimeMillis() - anaLastPageSceneEnterTs > 8000
        && System.currentTimeMillis() - xLastUnknownTs > 8000
        && System.currentTimeMillis() - anaLastHasEnemyNameTs > 4000
        && System.currentTimeMillis() - lastEliteEnemyBossTs > 4000
        && blockBlueDoor != null
        && blockBlacksmith != null
        && !bsSceneSettle && !bsSceneSettleBlacksmith
        && simpleAssertSceneCompleted(blockBlueDoor, blockBlacksmith)) {
        printLog { "analyst scene completed count $anaCounterSceneSettle" }
        anaCounterSceneSettle++
        if (anaCounterSceneSettle > 0) {
            printLog { "analyst scene completed" }
            anaMarkSceneSettle()
        }
    }
    if (System.currentTimeMillis() - lastBlueDoorTs > 3000
        && System.currentTimeMillis() - lastBlacksmithTs > 3000) {
        anaCounterSceneSettle = 0
    }
}

private val cJLP1StartA1 by lazy { Block("激流起点检测outA1", selfInSmallMap.x - 10.pt, selfInSmallMap.y - 40.pt, 20.pt, 20.pt) }
private val cJLP1StartA2 by lazy { Block("激流起点检测outA2", selfInSmallMap.x + 36.pt, selfInSmallMap.y - 36.pt, 36.pt, 20.pt) }
private val cJLP1StartA3 by lazy { Block("激流起点检测outA3", selfInSmallMap.x - 50.pt, selfInSmallMap.y - 5.pt, 20.pt, 40.pt) }
private val cJLP1StartA4 by lazy { Block("激流起点检测outA4", selfInSmallMap.x - 24.pt, selfInSmallMap.y + 46.pt, 20.pt, 20.pt) }
private val cJLP1StartA5 by lazy { Block("激流起点检测inA5", selfInSmallMap.x + 52.pt, selfInSmallMap.y + 40.pt, 30.pt, 16.pt) }
private val cJLP1StartA6 by lazy { Block("激流起点检测inA6主", selfInSmallMap.x + 58.pt, selfInSmallMap.y + 26.pt, 30.pt, 14.pt) }
private val hitStartRoad by lazy { setOf(0xff3C392E.toInt().rgb(12)) }
private val hitStartPrimaryRoad by lazy { setOf(0xff4A4538.toInt().rgb(12)) }

fun analysisMapJLIsStartPoint(ss: Bitmap): Boolean {
    if (System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
        && System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
    ) {
        var hitPart = 0
        //  hit [jlP5] 0.9 hitCount 36 total 40
        //  hit [jlP6] 0.78125 hitCount 25 total 32
        if (!Analysis.hit(ss, cJLP1StartA1, hitStartRoad, 4.pt, 0.1f  )) hitPart++ // , "jlP1"
        if (!Analysis.hit(ss, cJLP1StartA2, hitStartRoad, 4.pt, 0.1f  )) hitPart++ // , "jlP2"
        if (!Analysis.hit(ss, cJLP1StartA3, hitStartRoad, 4.pt, 0.1f  )) hitPart++ // , "jlP3"
        if (!Analysis.hit(ss, cJLP1StartA4, hitStartRoad, 4.pt, 0.1f  )) hitPart++ //  "jlP4"
        if (Analysis.hit(ss, cJLP1StartA5, hitStartRoad, 4.pt, 0.45f )) hitPart++ // , "jlP5"
        if (Analysis.hit(ss, cJLP1StartA6, hitStartPrimaryRoad, 4.pt, 0.45f )) hitPart++ // , "jlP6"
        if (hitPart >= 6) { // 识别好慢
            printLog { "analystJL 节点.激流路线是起点A" }
            anaLastSMapJLFeature8Ts = System.currentTimeMillis()
            anaClearSceneSettle()
            return true
        }
    }

    val bbd = blockBlueDoor
    if (bbd != null && blockBlacksmith == null) {
        if (System.currentTimeMillis() - lastMapTopNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapBottomNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapLeftNotArrivedTs > 2000
            && System.currentTimeMillis() - lastMapRightNotArrivedTs < 1000
            && lastMapTopP == null
            && lastMapBottomP == null
            && lastMapLeftP == null
            && (lastMapRightP ?: -1f) in 0.37 .. 0.46
            && blockBlueDoor != null
        ) {
            // [上,1746153675s,c:0][下,1746153675s,c:0][左,1746153675s,c:0][右,0s,0.4303233,c:23]][Road,c:25]
            // [上,54s,c:0][下,54s,c:0][左,54s,c:0][右,0s,0.40384614,c:22]][Road,c:25]
            // [上,1746154527s,c:0][下,1746154527s,c:0][左,1746154527s,c:0][右,0s,0.43492618,c:22]][Road,c:25]
            printLog { "analystJL 节点.激流路线是起点B" }
            anaLastSMapJLFeature8Ts = System.currentTimeMillis()
            anaClearSceneSettle()
            return true
        }
        else {
            val cStartPoint1 = Block("激流起点检测1", bbd.x + 50.pt, bbd.y + 36.pt, 16.pt, 16.pt)
            val cStartPoint2 = Block("激流起点检测2", bbd.x + 70.pt, bbd.y + 42.pt, 16.pt, 16.pt)
            val cStartPoint3 = Block("激流起点检测3", bbd.x + 90.pt, bbd.y + 46.pt, 16.pt, 16.pt)
            val cStartPoint4 = Block("激流起点检测4", bbd.x + 110.pt, bbd.y + 42.pt, 16.pt, 16.pt)
            val cStartPoint5 = Block("激流起点检测5", bbd.x + 130.pt, bbd.y + 30.pt, 16.pt, 16.pt)
            val cStartPoint6 = Block("激流起点检测6", bbd.x + 150.pt, bbd.y + 10.pt, 16.pt, 16.pt)
            var hitPart = 0  // hit [road1] 0.8 hitCount 20 total 25
            if (Analysis.hit(ss, cStartPoint1, hitRoad, 4.pt, 0.24f)) hitPart++ // , "startRoad1" // 0.5
            if (Analysis.hit(ss, cStartPoint2, hitRoad, 4.pt, 0.24f)) hitPart++ // , "startRoad2" // 0.66
            if (Analysis.hit(ss, cStartPoint3, hitRoad, 4.pt, 0.24f)) hitPart++ // , "startRoad3" // 0.66
            if (Analysis.hit(ss, cStartPoint4, hitRoad, 4.pt, 0.24f)) hitPart++ // , "startRoad4" // 0.44
            if (Analysis.hit(ss, cStartPoint5, hitRoad, 4.pt, 0.24f)) hitPart++ // , "startRoad5" // 0.77
            if (Analysis.hit(ss, cStartPoint6, hitRoad, 4.pt, 0.24f)) hitPart++ // , "startRoad6" // 0.77
            if (hitPart >= 5) {
                printLog { "analystJL 节点.激流路线是起点C" }
                anaLastSMapJLFeature8Ts = System.currentTimeMillis()
                anaClearSceneSettle()
                return true
            }
        }
    }
    return false
}

private fun simpleAssertSceneCompleted(blueDoor: Block?, blacksmith: Block?): Boolean {
    if (blueDoor == null) return false
    if (blacksmith == null) return false
    val edge = 80.pt
    return abs(blueDoor.x - blacksmith.x) < edge && abs(blueDoor.y - blacksmith.y) < edge
}

private fun angleSpecialAdjust(angle: Int): Int {
    if (angle in 170 .. 280) {
        if (System.currentTimeMillis() - xLastAtkTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyBossTs > 5000
            && System.currentTimeMillis() - lastEliteEnemyTs > 5000
            && System.currentTimeMillis() - anaLastSMapJLFeature1Ts > 20000 // 地图特征 条件
            && System.currentTimeMillis() - anaLastSMapJLFeature2Ts > 20000
            && System.currentTimeMillis() - anaLastSMapJLFeature3Ts > 20000
            && System.currentTimeMillis() - anaLastSMapJLFeature5Ts > 150000 //150s
            && System.currentTimeMillis() - anaLastSMapJLFeature7Ts > 20000
            && System.currentTimeMillis() - xLastSceneEnterTs > 30000
            && System.currentTimeMillis() - xLastPetBlacksmithTs > 20000
            && System.currentTimeMillis() - xLastUnknownTs < 20000) {
            printLog { "analystJL angleSpecialAdjust $angle to 45" }
            return 45
        }
    }
    return angle
}